/**
 * @file WebPage.hpp
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2022-04-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include <map>
#include <set>
#include <string>
#include <vector>

using std::map;
using std::set;
using std::string;
using std::vector;

namespace wd
{
class Configuration;
class WordSegmentation;

// 文档预处理类
// 网页去重 TopK -> 重建网页库 偏移库
// 建立倒排索引
class WebPage
{
    friend bool operator==(const WebPage &lhs, const WebPage &rhs);
    friend bool operator<(const WebPage &lhs, const WebPage &rhs);

  public:
    const static int TOPK_NUMBER = 20;

    WebPage(string &doc, Configuration &config, WordSegmentation &jieba);

    int getDocId()
    {
        return _docId;
    }

    map<string, int> &getWordsMap()
    {
        return _wordsMap;
    }

    string getDoc()
    {
        return _doc;
    }

  private:
    void processDoc(const string &doc, Configuration &config, WordSegmentation &jieba);

    void calcTopK(vector<string> &wordsVec, int k, set<string> &stopWordList);

  private:
    string _doc;
    int _docId;         //文档id
    string _docTitle;   //文档标题
    string _docUrl;     //文档URL
    string _docContent; //文档内容
    string _docSummary; //文档摘要，需要自动生成，不是确定的

    vector<string> _topWords;
    map<string, int> _wordsMap; // 存储文档的所有词(去停用词之后)和该项词的词频
};

} // end of namespace wd
